from selenium.webdriver.common.by import By

from base.page_base import BasePage


class CreditApplication(BasePage):
    __switch_account = (By.XPATH, "//em[text()='借款账户']")
    __account_apply = (By.LINK_TEXT, '申请额度')
    __amount = (By.ID, "amount_account")
    __detail_msg = (By.NAME, 'remark')
    __img_code = (By.NAME, 'verifycode')
    __confirm_btn = (By.CSS_SELECTOR, '.btn-submit.btn-md')
    __confirm_text = (By.XPATH, '//*[@id="amount_list"]/tr/td[3]')

    def switch_account_01(self):
        self.base_click(self.__switch_account)

    def account_apply_01(self):
        self.base_click(self.__account_apply)

    def amount_01(self, amount):
        self.base_input(self.__amount, amount)

    def detail_msg_01(self, detail_msg):
        self.base_input(self.__detail_msg, detail_msg)

    def img_code_01(self, img_code):
        self.base_input(self.__img_code, img_code)

    def confirm_btn_01(self):
        self.base_click(self.__confirm_btn)

    def credit_application(self, amount, detail_msg, img_code):
        self.switch_account_01()
        self.account_apply_01()
        self.amount_01(amount)
        self.detail_msg_01(detail_msg)
        self.img_code_01(img_code)
        self.confirm_btn_01()

    def get_credit_result(self):
        return self.fd_element(self.__confirm_text).text
